package com.example.demo.game.plane;

public class Vec {
    public double x, y;

    public Vec(double x, double y) {
        this.x = x;
        this.y = y;
    }

    public Vec add(Vec vec) {
        return new Vec(x + vec.x, y + vec.y);
    }

    public Vec sub(Vec vec) {
        return new Vec(x - vec.x, y - vec.y);
    }

    public double doc(Vec vec) {
        return x * vec.x + y * vec.y;
    }

    public Vec mul(double a) {
        return new Vec(x * a, y * a);
    }

    public double cross(Vec vec) {
        return x * vec.y - y * vec.x;
    }

    public double len() {
        return Math.sqrt(x * x + y * y);
    }

    public double dis(Vec vec) {
        return this.sub(vec).len();
    }

    public Vec normal() {
        double d = this.len();
        return new Vec(x / d, y / d);
    }

    public double rad() {
        if (x == 0) {
            return y > 0 ? Math.PI / 2 : -Math.PI / 2;
        }
        double tan = x / y;
        return Math.atan(tan);
    }
}
